package com.landinfo.service.impl;

import com.landinfo.service.TaskManagementService;
import com.landinfo.domain.TaskManagement;
import com.landinfo.repository.TaskManagementRepository;
import com.landinfo.service.dto.TaskManagementDTO;
import com.landinfo.service.mapper.TaskManagementMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Service Implementation for managing TaskManagement.
 */
@Service
@Transactional
public class TaskManagementServiceImpl implements TaskManagementService{

    private final Logger log = LoggerFactory.getLogger(TaskManagementServiceImpl.class);

    private final TaskManagementRepository taskManagementRepository;

    private final TaskManagementMapper taskManagementMapper;

    public TaskManagementServiceImpl(TaskManagementRepository taskManagementRepository, TaskManagementMapper taskManagementMapper) {
        this.taskManagementRepository = taskManagementRepository;
        this.taskManagementMapper = taskManagementMapper;
    }

    /**
     * Save a taskManagement.
     *
     * @param taskManagementDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public TaskManagementDTO save(TaskManagementDTO taskManagementDTO) {
        log.debug("Request to save TaskManagement : {}", taskManagementDTO);
        TaskManagement taskManagement = taskManagementMapper.toEntity(taskManagementDTO);
        taskManagement = taskManagementRepository.save(taskManagement);
        return taskManagementMapper.toDto(taskManagement);
    }

    /**
     *  Get all the taskManagements.
     *
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public List<TaskManagementDTO> findAll() {
        log.debug("Request to get all TaskManagements");
        return taskManagementRepository.findAll().stream()
            .map(taskManagementMapper::toDto)
            .collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     *  Get one taskManagement by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public TaskManagementDTO findOne(Long id) {
        log.debug("Request to get TaskManagement : {}", id);
        TaskManagement taskManagement = taskManagementRepository.findById(id).get();
        return taskManagementMapper.toDto(taskManagement);
    }

    /**
     *  Delete the  taskManagement by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete TaskManagement : {}", id);
        taskManagementRepository.deleteById(id);
    }
}
